Skip to content

BUG: head and tail not dropping groups with nan #45102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2021
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Dec 28, 2021

We could also create a specific function for this.

Also that nth respects as_index while it is ignored by head and tail looks inconsistent

@@ -894,6 +894,7 @@ Groupby/resample/rolling
- Bug in :meth:`GroupBy.nth` failing on ``axis=1`` (:issue:`43926`)
- Fixed bug in :meth:`Series.rolling` and :meth:`DataFrame.rolling` not respecting right bound on centered datetime-like windows, if the index contain duplicates (:issue:`3944`)
- Bug in :meth:`Series.rolling` and :meth:`DataFrame.rolling` when using a :class:`pandas.api.indexers.BaseIndexer` subclass that returned unequal start and end arrays would segfault instead of raising a ``ValueError`` (:issue:`44470`)
- Bug in :meth:`GroupBy.head` and :meth:`GroupBy.tail` no dropping groups with ``NaN`` when ``dropna=True`` (:issue:`45089`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no -> not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx


result = df.groupby(["X", "Y"]).tail(n=1)
tm.assert_frame_equal(result, expected)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test nth here as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jreback
Copy link
Contributor

jreback commented Dec 29, 2021

We could also create a specific function for this.

what does this mean

@phofl
Copy link
Member Author

phofl commented Dec 29, 2021

Adjusting the mask for the dropna flag in a dedicated function, because the place I put this is a bit awkward

@jreback jreback added this to the 1.4 milestone Dec 30, 2021
@jreback jreback merged commit db6a491 into pandas-dev:master Dec 30, 2021
@phofl phofl deleted the 45089 branch December 30, 2021 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: df.groupby().head() missing rows when grouping on several columns with NA
2 participants